/*
ID: icerupt1
PROG: heritage
LANG: C++11
*/

/* solution
 *
 *
 *
*/
#include <fstream>
#include <iostream>

std::ifstream fin {"heritage.in" };
std::ofstream fout{"heritage.out"};

std::string in_order;
std::string pre_order;

void post_order(std::string const & in_order, std::string const & pre_order)
{
	if (pre_order == "") return;
	auto root_pos = in_order.find(pre_order[0]);
	post_order(in_order.substr(0, root_pos), pre_order.substr(1, root_pos));
	post_order(in_order.substr(root_pos+1), pre_order.substr(1+root_pos));
	std::cout << pre_order[0]; fout << pre_order[0];
}

int main()
{
	fin >> in_order >> pre_order;
	post_order(in_order, pre_order);
	std::cout << '\n'; fout << '\n';
}

